﻿using System;
using System.Data;
using System.Data.SqlClient;


  public class Sql
    {
      private SqlConnection _con;
      public static string Connection;
      public SqlConnection OpenSqlConnectionExpress(string StringConnection)
      {
          try {
              Connection = plvs.Login.Settingslogin.Default.StringConnectionSQLManagenet;
              _con = new SqlConnection(Connection);
              if (_con.State != ConnectionState.Open)
                  _con.Open();
              else
                  _con.Close();
              return _con;
          }
          catch(Exception ex)
  {
      throw new Exception("Error 1040" + "\n" + ex.Message);
  }
      }
      public SqlConnection CloseSqlConnectionExpress(string StringConnection)
      {
          try
          {
              Connection = plvs.Login.Settingslogin.Default.StringConnectionSQLManagenet;
              _con = new SqlConnection(Connection);
              if (_con.State != ConnectionState.Open)
                  _con.Close();
              else
                  _con.Dispose();
              return _con;
          }
          catch (Exception ex)
          {
              throw new Exception("Error 1030"+"\n" + ex.Message);
          }
      }
      public SqlConnection OpneSqlConcetion()
      {
          Connection = plvs.Login.Settingslogin.Default.StringConnectionSQLManagenet;
          _con = new SqlConnection(Connection);
          try
          {
              if (_con.State != ConnectionState.Open)
                  _con.Open();
              return _con;
          }
          catch (Exception ex)
          {
              throw new Exception("Error 1010" + "\n" + ex.Message);
          }
          return _con;
          
      }

      public SqlConnection CloseSqlConcetion()
      {
          _con = new SqlConnection(Connection);
          try
          {
              if (_con.State != ConnectionState.Closed)
                  _con.Close();
              return _con;
          }
          catch (Exception ex)
          {
              throw new Exception("Error 1020" + "\n" + ex.Message);
          }
          return _con;
      }
    }

